package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.AddressDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Address;
import com.itheima.pojo.Setmeal;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: 张志飞
 * @Date: 今天是 2020/9/25     现在是23:29
 */

@Service(interfaceClass = AddressService.class)
public class AddressServiceImpl implements AddressService{

    @Autowired
    private AddressDao addressDao;




    @Override
    public void add(Address address) {
        addressDao.addAddress(address);
    }

    @Override
    public List<Address> findAddress() {
       return addressDao.findAddress();
    }

    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<Address> page = addressDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void edit(Address address) {
        addressDao.editAddress(address);
    }

    @Override
    public Address findById(Integer id) {
        return addressDao.findById(id);
    }

    @Override
    public void delete(Integer id) {
        long count = addressDao.findOrderCountByAddressId(id);
        if(count>0){
            throw new RuntimeException("该机构地址正在使用中，不能删除！");
        }
        addressDao.delete(id);

    }
}
